package io.zhiller.storagedemo.storage.db

import androidx.room.Database
import androidx.room.RoomDatabase
import io.zhiller.storagedemo.storage.dao.NoteDAO
import io.zhiller.storagedemo.storage.domain.Note
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@Database(
  entities = [Note::class],
  version = 1,
  exportSchema = false
)
abstract class RoomDB : RoomDatabase() {

  companion object {
    fun initialize(scope: CoroutineScope, database: RoomDB?) = scope.launch {
      val list = listOf(
        Note("Note 1", "This is a note"),
        Note("Note 2", "This is a note"),
      )
      database?.getNoteDao()?.insert(list)
    }
  }

  abstract fun getNoteDao(): NoteDAO

  fun clearDatabases() {
    clearAllTables()
  }
}